package array

import "fmt"

func test(x [2]int)  {
	fmt.Printf("x:%p\n",&x)
	x[1]=1000
}
func printArr(arr *[5]int)  {
	arr[0]=10
	for i,v :=range arr{
		fmt.Println(i,v)
	}
}
func slice()  {
	a:=[2]int{}
	fmt.Printf("a:%p\n",&a)

	test(a)
	fmt.Println(a)
	println(len(a),cap(a))

	//多维数组
	var f [2][3]int = [...][3]int{{1,2,3},{7,8,9}}
	for k1,v1:=range f{
		for k2,v2 :=range v1{
			fmt.Printf("(%d,%d)=%d ", k1,k2,v2)
		}; fmt.Println()
	}

	//数组拷贝和传参
	var arr1 [5]int
	printArr(&arr1)
	fmt.Println(arr1)
	arr2:=[...]int{2,4,6,8,10}
	printArr(&arr2)
	fmt.Println(arr2)

	//声明切片
	var s1 []int
	fmt.Println(s1!=nil)
	s2:= []int{}
	var s3 []int = make([]int,0)
	fmt.Println(s1,s2,s3)
	var s4 []int =make([]int,0,0)
	s5 := []int{1,2,3}
	fmt.Println(s4,s5)
	arr3 := [5]int{1,2,3,4,5}
	var s6 []int
	//注意前包后不包
	s6 = arr3[1:4]
	fmt.Println(s6)

	arr4 := [...]int{9,8,7,6,5,4,3,2,1,0}
	slice1:=arr4[1:6]
	slice2:=arr4[:6]
	slice3:=arr4[1:]
	slice4:=arr4[:]
	slice5:=arr4[:len(arr4)-1]
	fmt.Println(slice1,slice2,slice3,slice4,slice5)
	
	var slice10 = make([]int,10)
	slice11 := make([]int, 10)
	slice12 := make([]int, 10, 10)
	fmt.Println(slice10)
	fmt.Println(slice11)
	fmt.Println(slice12)

	s000:=[]int{0,1,2,3,4}
	p000:=&s000[2]
	*p000+=100
	fmt.Println(s000)

	data:= [][]int{
		{1, 2, 3},
		{100, 200},
		{11, 22, 33, 44},
	};fmt.Println(data)

	data1:=[5]struct{
		x int
	}{}
	sData1 :=data1[:]
	data1[1].x=10
	sData1[2].x=20
	fmt.Println(data1)
	fmt.Printf("%p,%p\n\n", &data1, &data1[0])

	//append
	var aAppend=[]int{1,2,3}
	var bAppend=[]int{4,5,6}
	cAppend:=append(aAppend,bAppend...)
	fmt.Printf("cAppend: %v\n",cAppend)
	dAppend:=append(cAppend,7)
	fmt.Printf("dAppend:%v\n",dAppend)

	strSlice:="hello world"
	strSlice1:=strSlice[0:5]
	fmt.Printf("strSlice1:%s\n",strSlice1)
	strSlice2:=strSlice[6:]
	fmt.Printf("strSlice2:%s\n",strSlice2)

	strSlice3:="你好!李银河            "
	strSlice4:=[]rune(strSlice3)
	strSlice4[6]='我'
	strSlice4[7]='很'
	strSlice4[8]='好'

	fmt.Println(string(strSlice4))



}

